package com.enzo.prms.common.util;


import org.apache.log4j.Logger;
import org.springframework.context.support.ResourceBundleMessageSource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil extends ResourceBundleMessageSource {
    public static final String CONFIG_PATH = "system-config.properties";
    protected static Logger logger = Logger.getLogger(PropertiesUtil.class);
    public static Properties properties = null;

    static {
        try {
            properties = new Properties();
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIG_PATH);
            if (is == null) {
                throw new RuntimeException("can't find the config file:" + CONFIG_PATH + "");
            }
            properties.load(is);
        } catch (IOException e) {
            logger.error("failed to read properties" + e.getMessage());
            throw new RuntimeException("failed to read " + CONFIG_PATH + e.getMessage());
        } catch (Exception e) {
            logger.error(e);
            logger.error("failed to decrypt properties" + e.getMessage());
        }
    }

    public static String getValue(String name) {
        return properties.getProperty(name);
    }

    public static String getValue(String name, String defaultValue) {
        String value = getValue(name);
        return StringUtil.isNotBlank(value) ? value : defaultValue;
    }
    
    public static void main(String[] args) {
		String str=getValue("mail.host.name");
		System.out.println(str);
	}

}
